package com.zlkj.pro.modular.admin.controller;

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import com.zlkj.pro.modular.admin.model.dto.MaterialGroupAdminDTO;
import com.zlkj.pro.modular.admin.model.vo.MaterialGroupAdminVO;
import com.zlkj.pro.modular.admin.service.MaterialGroupAdminService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.zlkj.pro.core.consts.ProjectConstants.BACKSTAGE_API_PREFIX;

/**
 * @author 孙铭泽
 * @date 2022/9/24
 * @time 14:34
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@ApiResource(name = "素材库分组管理", path = BACKSTAGE_API_PREFIX + "/materialGroup")
public class MaterialGroupAdminController {

    private final MaterialGroupAdminService materialGroupAdminService;

    @GetResource(name = "分页查询", path = "/findPage")
    public ResponseData findPage(MaterialGroupAdminDTO materialGroupAdminDTO) {
        PageResult<MaterialGroupAdminVO> restData = materialGroupAdminService.findPage(materialGroupAdminDTO);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "查询列表", path = "/findList")
    public ResponseData findList(MaterialGroupAdminDTO materialGroupAdminDTO) {
        List<MaterialGroupAdminVO> restData = materialGroupAdminService.findList(materialGroupAdminDTO);
        return new SuccessResponseData(restData);
    }

    @GetResource(name = "查询详情", path = "/findDetail")
    public ResponseData findDetail(MaterialGroupAdminDTO materialGroupAdminDTO) {
        MaterialGroupAdminVO restData = materialGroupAdminService.findDetail(materialGroupAdminDTO);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "添加", path = "/add")
    public ResponseData add(@RequestBody MaterialGroupAdminDTO materialGroupAdminDTO) {
        boolean restData = materialGroupAdminService.add(materialGroupAdminDTO);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "编辑", path = "/edit")
    public ResponseData edit(@RequestBody MaterialGroupAdminDTO materialGroupAdminDTO) {
        boolean restData = materialGroupAdminService.edit(materialGroupAdminDTO);
        return new SuccessResponseData(restData);
    }

    @PostResource(name = "删除", path = "/delete")
    public ResponseData delete(@RequestBody MaterialGroupAdminDTO materialGroupAdminDTO) {
        boolean restData = materialGroupAdminService.delete(materialGroupAdminDTO);
        return new SuccessResponseData(restData);
    }

}
